<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('新增横向课题得分配置')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
  <form class="form-horizontal m" id="form-projectScoreCfg-add">
    <h4 class="form-header h4">经费区间</h4>
    <div class="form-group">
      <label class="col-sm-2 control-label">经费小于：</label>
      <div class="col-sm-4">
        <input name="fundsMax" id="fundsMax" class="form-control" type="text">
      </div>

      <label class="col-sm-2 control-label">经费大于：</label>
      <div class="col-sm-4">
        <input name="fundsMin" id="fundsMin" class="form-control" type="text">
      </div>
    </div>
<!--    <div class="form-group">-->
<!--      <label class="col-sm-2 control-label">课题类型：</label>-->
<!--      <div class="col-sm-4">-->
<!--        <select name="projectType" class="form-control">-->
<!--          <option value="H">横向课题</option>-->
<!--          &lt;!&ndash;                    <option value="V">校内课题</option>&ndash;&gt;-->
<!--        </select>-->
<!--      </div>-->
<!--    </div>-->
    <h4 class="form-header h4">负责人得分配置</h4>
    <div class="col-sm-12 ">
      <table id="bootstrap-table" class="table table-bordered table-hover">
        <thead>
        <tr>
          <th>负责人顺序</th>
          <th>总分</th>
          <th>开题得分</th>
          <th>结题得分</th>
        </tr>
        </thead>
        <tr>
          <td>1 <input type="hidden" name="userOrder" id="userOrder1" value="1"></td>
          <td><input type="number" name="totalScore" id="totalScore1" data-user-order="1"
                     class="form-control"></td>
          <td><input type="number" name="startScore" id="startScore1"
                     class="form-control" readOnly></td>
          <td><input type="number" name="endScore" id="endScore1"
                     class="form-control" readOnly></td>
        </tr>
        <tr>
          <td>2<input type="hidden" name="userOrder" id="userOrder2" value="2"></td>
          <td><input type="number" name="totalScore" id="totalScore2" class="form-control"
                     data-user-order="2"></td>
          <td><input type="number" name="startScore" id="startScore2" class="form-control" readOnly></td>
          <td><input type="number" name="endScore" id="endScore2" class="form-control" readOnly></td>
        </tr>
        <tr>
          <td>3<input type="hidden" name="userOrder" id="userOrder3" value="3"></td>
          <td><input type="number" name="totalScore" id="totalScore3" class="form-control"
                     data-user-order="3"></td>
          <td><input type="number" name="startScore" id="startScore3" class="form-control" readOnly></td>
          <td><input type="number" name="endScore" id="endScore3" class="form-control" readOnly></td>
        </tr>
        <tr>
          <td>4<input type="hidden" name="userOrder" id="userOrder4" value="4"></td>
          <td><input type="number" name="totalScore" id="totalScore4" class="form-control"
                     data-user-order="4"></td>
          <td><input type="number" name="startScore" id="startScore4" class="form-control" readOnly></td>
          <td><input type="number" name="endScore" id="endScore4" class="form-control" readOnly></td>
        </tr>
      </table>
    </div>
  </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
  var prefix = ctx + "system/tec_tra"
  $("#form-projectScoreCfg-add").validate({
    focusCleanup: true
  });
  checkScore();

  function checkScore() {

    $("input[name='totalScore']").blur(function () {
      var totalScore = $(this).val();
      if ('' == totalScore) {
        return;
      }

      var user_order = $(this).data("user-order");
      var startScore = Math.round(totalScore * 0.7);
      var endScore = Math.round(totalScore * 0.3);

      $("#startScore" + user_order).val(startScore);
      $("#endScore" + user_order).val(endScore);
    })
  }

  function submitHandler() {
    var fundsMax = $("#fundsMax").val();
    if (fundsMax == "") {
      alert("经费最大值必须填写，若无上限填0！");
      return;
    }
    var fundsMin = $("#fundsMin").val();
    if (fundsMin == "") {
      alert("经费最小值必须填写，若无下限填0！");
      return;
    }

    let check_result = true;
    $("input[name='totalScore']").each(function () {
      var totalScore = $(this).val();
      if ('' == totalScore) {
        check_result = false;
      }
    });
    if (true != check_result) {
      alert("总分必须填写");
      return;
    }

    if ($.validate.form()) {
      var formData = new FormData(document.getElementById("form-projectScoreCfg-add"));

      $.ajax({
        url: prefix + "/add",
        data: formData,
        type: "post",
        processData: false,
        contentType: false,
        success: function (result) {
          $.modal.msgSuccessReload("操作成功")
        }
      })

    }
  }
</script>
</body>
</html>